// 添加核酸余量
<template>
    <div v-loading="loading">
    <el-form :inline="true" :model="nucleicAddForm">
        <el-form-item label="添加数量">
            <el-input v-model="nucleicAddForm.addNum" />
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="onAdd">添加</el-button>
        </el-form-item>
    </el-form>
    <el-card class="disp-card">
        <template #header>
            <div class="card-header">
                <span> 目前核酸余量： </span>
            </div>
        </template>
        <div class="item-big"> {{curNum}} 支 </div>
    </el-card>
    </div>
</template>

<script>
import {Request} from '../../utils/request'
import {ElMessage} from 'element-plus'

export default {
    name: 'NucleicAdd',
    data() {
        return {
            nucleicAddForm: {
                addNum: ''
            },
            curNum: undefined,
            loading: true
        }
    },
    created() {this.reload()},
    methods: {
        reload() {
            this.loading = true
            Request({
                url: '/nucleic-acid-add',
                method: 'get'
            }).then(res => {
                this.curNum = res.number
                this.loading = false
            })
        },
        onAdd() {
            Request({
                url: '/nucleic-acid-add',
                method: 'post',
                data: {number: this.nucleicAddForm.addNum}
            }).then(res => {
                if(res === 'success') {
                    ElMessage({
                        message: '添加成功',
                        type: 'success'
                    })
                    this.nucleicAddForm.addNum = ''
                    this.reload()
                }
                else if (res) {
                    ElMessage({
                        message: '错误：' + res,
                        type: 'error'
                    })
                }
            })
        },
    }
}
</script>

<style>
.disp-card {
    width: 480px;
    margin-top: 20px;
    margin-left: 20px;
}

.item-big {
    font-size: 18;
    font-weight: bold;
}
</style>